﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Drawing;

namespace PO_2011.ImageHistory
{
    public class History
    {
        private static Bitmap[] bitmap;
        private static int bitmap_iterator = 0;
        private static int max_history = 10;
        private static int max_returned_iterator = 0;

        public static void addStep(Bitmap img)
        {
            createBitmapArray();
            /*
            bitmap[bitmap_iterator] = new Bitmap(img);
            bitmap_iterator++;

            if (bitmap_iterator % max_history == 0)
            {
                bitmap_iterator = 0;
            }
            */
            bitmap[0] = new Bitmap(img);
        }

        public static Bitmap returnLastImage()
        {
          /*  createBitmapArray();

            // Jesli jest na poczatku listy to sprawdzic czy ostatni element nie jest pusty, poniewaz zapisywanych jest ostatnich 10 zmian, a potem petla.
            bitmap_iterator--;

            if ((bitmap_iterator - 1) <= -1)
            {
                if (bitmap[max_history - 1] != null)
                {
                    bitmap_iterator = max_history - 1;
                    return popBitmap();
                }
                else if (bitmap[0] != null)
                {
                    bitmap_iterator = 0;
                    return popBitmap();
                }
                else
                {
                    bitmap_iterator = 0;
                    return popBitmap();
                }
            }

            --bitmap_iterator;
            return popBitmap(); */

            if (bitmap != null) return bitmap[0];
            else return null;
        }

        private static void createBitmapArray()
        {
            if (bitmap == null)
            {
                bitmap = new Bitmap[max_history];
            }
        }

        private static Bitmap popBitmap()
        {
            Bitmap temp = bitmap[bitmap_iterator];
            bitmap[bitmap_iterator] = null;

            return temp;
        }

    }
}
